<?php
/**
 * Created by PhpStorm.
 * User: Zhoujinda
 * Date: 2015/12/31
 * Time: 15:31
 */

namespace Api\Domain;


use Jsq\Api\HistoryApi;

class JsqDbDomain extends BaseDomain{
    protected $business_code = 'JsqDb';

    protected $allowType = array("json", "rss", "html");


    /**
     * 净水器历史数据查询
     */
    public function historyQuery(){

        addLog("JsqDb/historyQuery",$_GET,$_POST,'应用'.$this->client_id."调用净水器历史数据查询接口");

        $this->checkVersion(100);

        if(IS_POST){

            $did = $this->_post('ddid',"",'设备唯一标识缺失');

            $result  = apiCall(HistoryApi::QUERY_NO_PAGING,array(array('did'=>$did)));

            if($result['status']){
                $this->apiReturnSuc($result['info']);
            }else{
                $this->apiReturnErr($result['info']);
            }

        }else{
            $this->apiReturnErr("只支持POST请求!");
        }

    }

    /**
     * 净水器天历史数据查询
     */
    public function historyDaysQuery(){

        addLog("JsqDb/historyDaysQuery",$_GET,$_POST,'应用'.$this->client_id."调用净水器天历史数据查询接口");

        $this->checkVersion(100);

        if(IS_POST){

            $did = $this->_post('ddid',"",'设备唯一标识缺失');

            $today = date('Y-m-d');

            $data = array();

            for($i=0;$i<15;$i++){

                array_push($data,array('date'=>(string)strtotime("$today - $i day"),'uf_flow'=>1000-$i*20,'ro_flow'=>1000-$i*25));

            }

            $result['status'] = true;
            $result['info'] = $data;


            if($result['status']){
                $this->apiReturnSuc($result['info']);
            }else{
                $this->apiReturnErr($result['info']);
            }

        }else{
            $this->apiReturnErr("只支持POST请求!");
        }

    }

    /**
     * 净水器月历史数据查询
     */
    public function historyMonthsQuery(){

        addLog("JsqDb/historyDaysQuery",$_GET,$_POST,'应用'.$this->client_id."调用净水器月历史数据查询接口");

        $this->checkVersion(100);

        if(IS_POST){

            $did = $this->_post('ddid',"",'设备唯一标识缺失');

            $this_month = date('Y-m');

            $data = array();

            for($i=0;$i<12;$i++){

                array_push($data,array('date'=>(string)strtotime("$this_month - $i month"),'uf_flow'=>10000-$i*200,'ro_flow'=>10000-$i*250));

            }

            $result['status'] = true;
            $result['info'] = $data;


            if($result['status']){
                $this->apiReturnSuc($result['info']);
            }else{
                $this->apiReturnErr($result['info']);
            }

        }else{
            $this->apiReturnErr("只支持POST请求!");
        }

    }


}